package com.study.rabbitmq.basic.key;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class KeyConsumerTest {
	public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost("192.168.20.68");
		factory.setPort(5672);
		factory.setUsername("leke");
		factory.setPassword("leke@@@");

		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel(5);

		String queueName = "keyQueue";
		String routingKey = "a.b.c";
		channel.queueDeclare(queueName,false,false,false,null);

		Consumer consumer = new DefaultConsumer(channel){
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
				System.out.println("consumer tag :" +consumerTag+"  "+new String(body));
				//channel.basicAck(envelope.getDeliveryTag(), false);

				channel.basicNack(envelope.getDeliveryTag(), false, false);
			}
		};
		//push  默认autoAck 为false
		String consumerTag = channel.basicConsume(queueName, consumer);


	}
}
